<%--
  Created by IntelliJ IDEA.
  User: Shinelon
  Date: 2020/11/12
  Time: 19:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<link rel="stylesheet" href="${pageContext.request.contextPath}/style/layui/css/layui.css">
<script src="${pageContext.request.contextPath}/style/layui/layui.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/style/jquery-2.1.0.js"></script>
<html>
<head>
    <title>房间列表</title>
</head>
<body>
    <button type="button" class="layui-btn" id="addbtn">
        <i class="layui-icon">&#xe608;</i> 添加
    </button>
    <table class="layui-hide" id="test" lay-filter="test"></table>


    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>

    <script>
        layui.use(['table','form'], function(){
            var table = layui.table;
            var form=layui.form;

            table.render({
                elem: '#test' //id为test的table
                ,url:'${pageContext.request.contextPath}/room?method=select'   //url 查询数据   所有的客户的数据
                ,title: '角色表'
                //data[{ id:12,name:123}]
                ,cols: [[
                    {field:'id', title:'ID',fixed: 'left',  sort: true}
                    ,{field:'roomcode', title:'房间号'}
                    ,{field:'name', title:'房间类型'}
                    ,{field:'status', title:'状态',  sort: false,templet: function(res){
                            //res  这一行的内容
                            var f=res.status;//状态值
                            if(f==0){
                                //正常
                                return "正常";
                            }else{
                                return "禁用";
                            }
                        }
                    }
                    ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
                ]]
                ,page: true
            });
            //监听行工具事件  test  表格的id
            table.on('tool(test)', function(obj){
                //obj 代表 一行的内容
                var data = obj.data; //一行的数据

                //console.log(obj)
                if(obj.event === 'del'){
                    layer.confirm('真的删除行么', function(index){
                        // obj.del();//页面删除
                        window.location.href="${pageContext.request.contextPath}/gust?method=del&id="+data.id;
                        layer.close(index);
                    });
                } else if(obj.event === 'edit'){
                    layui.use('layer', function(){
                        var layer = layui.layer;
                        layer.open({
                            title:'修改信息'
                            ,type: 1
                            ,content:$('#popUpdateTest')
                            ,offset: '100px'
                            ,moveOut:true
                            ,area: ['500px', '450px']

                        });
                        form.val('upd', {
                            "id": data.id // "name": "value"
                            ,"name": data.name
                            ,"pwd": data.pwd
                            ,"idcard": data.idcard
                            ,"status": data.status
                        });
                    })
                }
            });
        });
    </script>
</body>
</html>
